class Sales::QuotationsController < ApplicationController
  before_action :set_sales_quotation, only: [:show, :edit, :update, :destroy]

  # GET /sales/quotations
  # GET /sales/quotations.json
  def index
    @sales_quotations = Sales::Quotation.all
  end

  # GET /sales/quotations/1
  # GET /sales/quotations/1.json
  def show
  end

  # GET /sales/quotations/new
  def new
    @sales_quotation = Sales::Quotation.new
  end

  # GET /sales/quotations/1/edit
  def edit
  end

  # POST /sales/quotations
  # POST /sales/quotations.json
  def create
    @sales_quotation = Sales::Quotation.new(sales_quotation_params)

    respond_to do |format|
      if @sales_quotation.save
        format.html { redirect_to @sales_quotation, notice: 'Quotation was successfully created.' }
        format.json { render :show, status: :created, location: @sales_quotation }
      else
        format.html { render :new }
        format.json { render json: @sales_quotation.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /sales/quotations/1
  # PATCH/PUT /sales/quotations/1.json
  def update
    respond_to do |format|
      if @sales_quotation.update(sales_quotation_params)
        format.html { redirect_to @sales_quotation, notice: 'Quotation was successfully updated.' }
        format.json { render :show, status: :ok, location: @sales_quotation }
      else
        format.html { render :edit }
        format.json { render json: @sales_quotation.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /sales/quotations/1
  # DELETE /sales/quotations/1.json
  def destroy
    @sales_quotation.destroy
    respond_to do |format|
      format.html { redirect_to sales_quotations_url, notice: 'Quotation was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_sales_quotation
      @sales_quotation = Sales::Quotation.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def sales_quotation_params
      params.require(:sales_quotation).permit(:firm_id, :code, :created_by, :system_price, :discount, :final_price, :plan_detail, :stage, :approve_by, :approve_at)
    end
end
